/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.raitcon.hibernate.db;

import com.raitcon.hibernate.bean.Nota;
import com.raitcon.hibernate.bean.NotaMensualProm;
import com.raitcon.hibernate.factory.HibernateUtil;
import java.util.List;
import org.apache.log4j.Logger;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author Mike
 */
public class NotaMensualPromDB {
    
    
    private Session session = null;
    
    
    public NotaMensualPromDB(){
        this.session = HibernateUtil.getSessionFactory().getCurrentSession();
    }
    
     protected static Logger log = Logger.getLogger(NotaMensualPromDB.class);
    
    
     public NotaMensualProm findNotaMensualProm(Long idAlumno, Integer idCronEval,Integer idAsignatura){
        
         log.info("Iniciando consulta de nota promedio...");
         NotaMensualProm notaMenProm=null;
        try {
            Transaction tx = session.beginTransaction();
            Query q = session.createQuery("from NotaMensualProm as notaMensualProm  "
                    + "WHERE id_alumno="+idAlumno+ " AND id_asignatura="+ idAsignatura+
                   " AND id_cronograma_evaluacion ="+idCronEval);

            notaMenProm=(NotaMensualProm) q.uniqueResult();
             log.info("Consulta de detalle nota exitosa.");
             return notaMenProm;
        } catch (Exception e) {
            log.error("Error:" + e.getMessage());
            e.printStackTrace();
        } finally {
            //session.close();
        }
        return notaMenProm;
    }
     
     
     public List<NotaMensualProm> getNotaPromedioMensualFilter(Long idNota){
        
         log.info("Iniciando consulta de NotaMensualProm...");
        List<NotaMensualProm> cedulaMatriculaList = null;
        try {
            Transaction tx = session.beginTransaction();
            Query q = session.createQuery("FROM NotaMensualProm as notaMensualProm "
                    + "WHERE id_nota="+idNota+" order by id_nota_mensual_prom" );

            cedulaMatriculaList = (List<NotaMensualProm>) q.list();
             log.info("Consulta de nota_mensual_prom nota exitosa.");
        } catch (Exception e) {
            log.error("Error:" + e.getMessage());
            e.printStackTrace();
        } finally {
            //session.close();
        }
        return cedulaMatriculaList;
    }
    
}
